package com.chengzhi.state;

import org.springframework.messaging.Message;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;

/**
 * @author ruanchengzhi
 * @description: 状态监听器
 * @date 2019/7/23 14:12
 */
@WithStateMachine
public class OrderBean {

    @OnTransition(source = "WAIT_PAYMENT",target = "WAIT_DELIVER")
    public Boolean pay(Message<OrderEvent> message) {
        Order order = (Order) message.getHeaders().get("order");
        order.setStatus(OrderStatus.WAIT_DELIVER);
        System.out.println("----------------PAY" + order);
        return Boolean.TRUE;
    }

    @OnTransition(source = "WAIT_DELIVER", target = "WAIT_RECEIVE")
    public Boolean receive(Message<OrderEvent> message) {
        Order order = (Order) message.getHeaders().get("order");
        order.setStatus(OrderStatus.WAIT_RECEIVE);
        System.out.println("---------------RECEIVE" + order);
        return Boolean.TRUE;
    }
    @OnTransition(source = "WAIT_RECEIVE", target = "FINISH")
    public Boolean finish(Message<OrderEvent> message) {
        Order order = (Order) message.getHeaders().get("order");
        order.setStatus(OrderStatus.FINISH);
        System.out.println("---------------RECEIVE" + order);
        return Boolean.TRUE;
    }
}
